/***********************************************************************
 *
 * MODULE NAME:    hfp_core.h
 * DESCRIPTION:    hfp core function define
 * AUTHOR:         Martin Mellody
 *
 * SOURCE CONTROL: $Id: hfp.h,v 1.1 2008/01/03 06:55:12 tianwq Exp $
 *
 * LICENSE:
 *     This source code is copyright (c) 2000-2011 RDA Microelectronics.
 *     All rights reserved.
 *
 ***********************************************************************/

#ifndef __HFP_CORE_H__
#define __HFP_CORE_H__


/*****************************************************************************/
/*                        Handsfree Feature Definitions                              */
/*****************************************************************************/
//AG supported features bit masks .
#define AG_FEATURE_THREE_WAY_CALLING                (1)
#define AG_FEATURE_NREC_FUNCTION                    (1<<1)
#define AG_FEATURE_VOICE_RECOGNITION                (1<<2)
#define AG_FEATURE_IN_BAND_RING                     (1<<3)
#define AG_FEATURE_VOICE_TAG                        (1<<4)
#define AG_FEATURE_REJECT_CALL                      (1<<5)
#define AG_FEATURE_ENHANCED_CALL_STATUS             (1<<6)
#define AG_FEATURE_ENHANCED_CALL_CONTROL            (1<<7)
#define AG_FEATURE_EXTENDED_ERROR_CODES             (1<<8)

/*Bits for HF_Modify_Remote_Supplementary_Feature(). */
//AG supported features bit masks .
#define HF_FEATURE_NREC_FUNCTION                    (1)
#define HF_FEATURE_CALL_WAIT                        (1<<1)
#define HF_FEATURE_CLIP                             (1<<2)
#define HF_FEATURE_VOICE_RECOGNITION                (1<<3)
#define HF_FEATURE_REMOTE_VOL                       (1<<4)
#define HF_FEATURE_ENHANCED_CALL_STATUS             (1<<5)
#define HF_FEATURE_ENHANCED_CALL_CONTROL            (1<<6)

/*******************************************
 *  SLC States
 *******************************************/
#define SCM_CLOSED 0
#define SCM_W4_INDICATOR_CONTROL_OK 1
#define SCM_W4_INDICATOR_STATUS 2
#define SCM_W4_INDICATOR 3
#define SCM_W4_CALL_HOLD_INFO_OK 4
#define SCM_W4_ENABLE_INDICATOR_STATUS_UPDATE_OK 5
#define SCM_W4_CALL_HOLD_INFO   6
#define SCM_W4_SUPPORTED_FEATURES 7
#define SCM_W4_INDICATOR_CONTROL 8
#define SCM_W4_INDICATOR_STATUS_OK  10
#define SCM_W4_RFCOMM_CONNECT 11
#define SCM_OPEN 12
#define SCM_W4_SUPPORTED_FEATURES_OK 13
#define SCM_W4_USER_ACCEPT 14
#define SCM_SDP_DISCOVERY_PENDING 15
#define SCM_W4_EXIT_SNIFF_PRIOR_TO_DISCONNECT 16
#define SCM_W4_RFCOMM_DISCONNECT_INDICATION  17



/***********************************************
 * Call States
 * Currently not complete and not extensively used
 *************************************************/
#define HFP_CALL_CLOSED                02
#define HFP_CALL_ESTABLISHMENT         04
#define HFP_CALL_W4_ADT_OK             10
#define HFP_CALL_W4_CIEV_CALL_SETUP_2  11
#define HFP_CALL_W4_CIEV_CALL_1        12
#define HFP_CALL_ACTIVE                13
#define HFP_CALL_W4_USER_ACCEPT        14
#define HFP_W4_PEER_CALL_CONNECT       15
#define HFP_LOCAL_USER_INIT_CALL_REJECT 16
#define HFP_LOCAL_USER_INIT_CALL_RELEASE 17
// Additional States for Call handling when acting as AG
#define HFP_CALL_RING                  20
#define HFP_CALL_ALERTING              21
#define HFP_CALL_ANSWERED              22

#define HFP_CALL_WAIT					23

/* handle at result */
#define HFP_HANDLE_AT_OK               0
#define HFP_HANDLE_AT_ERROR            1
#define HFP_HANDLE_AT_UNKNOWN          2

/********************************************************************
 * Default Version
 ********************************************************************/
#define BT_HFP_PROTOCOL_VERSION 0x0105

/********************************************************************
 * Default MAX Size and Timeout values
 ********************************************************************/
#define MAX_PHONE_NUMBER     48
#define RDABT_HFP_MAX_DTMF_STRING_SIZE 20

#define RDABT_HFP_SLC_SETUP_TIMEOUT  100  // 10 seconds ( has to be larger than the L2CAP RTX timeout : RDABT_L2_RTX_TIMEOUT_VALUE:32s)
#define RDABT_HFP_RING_TIMEOUT      20  // 2 Seconds between rings
#define HFP_FLAG_CLIP_ENABLE            1
#define HFP_FLAG_CIEV_ENABLE            2
#define HFP_FLAG_CALL_WAIT_ENABLE       4

#ifndef BD_ADDR_CMP
#define BD_ADDR_CMP(x,y) !pMemcmp(((x).bytes), ((y).bytes), 6)
#endif
/*************************************
 *  t_HFP
 *
 *  Structure to save hfp state.
 *
 *************************************/
typedef struct 
{
    t_bdaddr address;                 // Bluetooth Address of the peer AG
    u_int8 scm_state;                 // Current State of the Service link to the peer
    u_int8 operation_pending;         // Current AT Command pending from the peer.
    u_int8 call_handling;  // 
    u_int8 serverChannel;
    u_int8 local_serverChannel;
    u_int16 versionInfo;
    u_int8 call_state;
    //u_int8 audio_state; // temp for hs

    u_int8 HFP_Browse_Pending;
    u_int8 service_ind_order;
    u_int8 call_setup_ind_order;
    u_int8 call_ind_order;         
    u_int8 service_ind;             //service availability indicator. 0/1: Home/Roam network not/available
    u_int8 call_ind;                  //call status indicator: 0:no call active, 1:a call is active
    u_int8 call_setup_ind;       //call setup indicator  // 0: not currently in call setup, 1: an incoming call process ongoing
    								// 2: an outgoing call setup process ongoing, 3: remote party being alerted in an outgoing call						

    u_int16 dlci;
    u_int8 rf_role;
    u_int8 remote_feature_status;
    u_int32 supportedFeatures;       // Features supported by the peer 
    u_int8 pending_data[50];//u_int8* pending_data; was used to save the AT command, so 50 bytes maybe enough. zhujianguo.
    u_int8 pending_data_len;
    u_int16 acl_handle;
    u_int8 HFP_TxOK;
    u_int8 slc_setup_timer_handle;
    u_int8 ring_timer;
    u_int8 active_profile;
    u_int8 num_Phone[MAX_PHONE_NUMBER];
    u_int8 num_length;
    u_int8 indicators_status[7];

	s_int8 is_iphone;
	u_int8 battery_percent;

    u_int8 flags;
} t_HFP;


/*******************************************************************/
/*                        Prototypes                               */
/*******************************************************************/
void hfp_initialise(void);
t_api rdabt_hfp_msg_dispatch(rdabt_msg_t *message);
t_api rdabt_hfp_layer_ctrl(u_int8 layerFlags);
#endif  //__HFP_CORE_H__


